package com.PGD.model.vos
{
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.events.CollectionEvent;
	import mx.events.CollectionEventKind;
	
	import uranrus.persistence.BazManaged;
	import uranrus.persistence.BazManagedCollection;
	
	public class AnswerSet extends BazManaged
	{
		public function AnswerSet()
		{
		}
		
		
		private var _questionSlideID:String;
		[Bindable(event="questionSlideIDChange")]
		public function set questionSlideID (value:String):void
		{
			if (value != _questionSlideID)
			{
				_questionSlideID = value;
				dispatchEvent (new Event ("questionSlideIDChange"));
			}
		}

		public function get questionSlideID ():String
		{
			return _questionSlideID;
		}

		private var _id:String;
		[Bindable(event="idChange")]
		override public function set id (value:*):void
		{
			if (value != _id)
			{
				_id = value as String;
				dispatchEvent (new Event ("idChange"));
			}
		}

		override public function get id ():*
		{
			return _id;
		}


		
		private var _setType:String;
		[Bindable(event="setTypeChange")]
		public function set setType (value:String):void
		{
			if (value != _setType)
			{
				_setType = value;
				dispatchEvent (new Event ("setTypeChange"));
			}
		}

		public function get setType ():String
		{
			return _setType;
		}

		private var _answers:BazManagedCollection;
		[Bindable(event="answersChange")]
		public function set answers (value:ArrayCollection):void
		{
			if (value != _answers)
			{
				if (_answers)
				{
					_answers.removeEventListener
						(CollectionEvent.COLLECTION_CHANGE, onAnswersChange);
					_answers.removeEventListener(BazManagedCollection.PROPERTY_UPDATED_EVENT, answerPropertyChangeHandler);
				}
				_answers = new BazManagedCollection(value.source);
				if (_answers)
				{
					_answers.addEventListener
						(CollectionEvent.COLLECTION_CHANGE, onAnswersChange);
					_answers.addEventListener(BazManagedCollection.PROPERTY_UPDATED_EVENT, answerPropertyChangeHandler)
				}
				dispatchEvent (new Event ("answersChange"));
			}
		}

		public function get answers ():ArrayCollection
		{
			return _answers;
		}

		private function onAnswersChange (event:CollectionEvent):void
		{
			if ((event.kind == CollectionEventKind.ADD) ||
				(event.kind == CollectionEventKind.REMOVE))
			{
				dispatchEvent (new Event ("answersChange"));
			}
		}

		private function answerPropertyChangeHandler(evt:Event):void
		{
			isDirty = true;
			trace("a property on my child answer object changed");
		}

	}
}